Skip to content

Implement GH-18261: Allow cast to be used in constant expressions #18264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 11, 2025

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Apr 6, 2025

No description provided.

@nielsdos nielsdos linked an issue Apr 6, 2025 that may be closed by this pull request
Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise.

@nielsdos nielsdos marked this pull request as ready for review April 10, 2025 20:58
@nielsdos nielsdos requested a review from dstogov as a code owner April 10, 2025 20:58
Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct to me now. Thank you!

UPGRADING Outdated
@@ -130,6 +130,7 @@ PHP 8.5 UPGRADE NOTES
RFC: https://wiki.php.net/rfc/marking_return_value_as_important
. Added asymmetric visibility support for static properties.
RFC: https://wiki.php.net/rfc/static-aviz
. It is now possible to use casts in constant expressions.
Copy link
Member

@iluuu1994 iluuu1994 Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "Added support for casts in constant expressions" for consistency?

case IS_OBJECT:
zend_cast_zval_to_object(result, &op1, IS_VAR);
break;
EMPTY_SWITCH_DEFAULT_CASE();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the new (void) cast?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Void casts are not allowed in expression context, only when their return value is not used. This never applies to constant expressions. This is also a different ast type (ZEND_AST_CAST_VOID), so it doesn't need to be handled here.

@nielsdos nielsdos merged commit 2f6c069 into php:master Apr 11, 2025
1 check passed
iluuu1994 added a commit to iluuu1994/php-src that referenced this pull request Apr 17, 2025
iluuu1994 added a commit to iluuu1994/php-src that referenced this pull request Apr 17, 2025
iluuu1994 added a commit to iluuu1994/php-src that referenced this pull request Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow cast to be used in constant expressions
4 participants